package other.one;

import other.one.advance.RoomRequest;
import other.one.advance.RoomServiceImplAdvance;
import other.one.advance.RoomServiceImplAdvance2;

import java.util.concurrent.CountDownLatch;

/**
 * 测试用例
 *
 * @author WangChenyu
 * @since 2024-04-17 15:25
 */
public class RoomServiceTest {


    public static void main(String[] args) throws InterruptedException {
        // 进阶版测试
        RoomServiceImplAdvance2 roomService = new RoomServiceImplAdvance2();
        roomService.operation(RoomRequest.leaveRoom("123","1",2));
        roomService.operation(RoomRequest.joinRoom("123","1",1));
        roomService.operation(RoomRequest.joinRoom("123","1",3));
        Thread.sleep(1000);
        System.out.println(roomService.queryUser("1"));
        // 得到结果后结束子线程
//        roomService.thread.interrupt();
        //------------------------------------------------------------------------
//        RoomServiceImplAdvance roomService2 = new RoomServiceImplAdvance();
//        roomService2.leaveRoom("2", "1");
//        roomService2.leaveRoom("2", "1");
//        roomService2.joinRoom("2", "1");
//        System.out.println(roomService2.queryUser("1"));
    }

    static class Exe implements Runnable {
        private final  CountDownLatch countDownLatch;
        private final RoomServiceImplAdvance roomService;

        public Exe(CountDownLatch countDownLatch, RoomServiceImplAdvance roomService) {
            this.countDownLatch = countDownLatch;
            this.roomService = roomService;
        }

        @Override
        public void run() {
//            roomService.leaveRoom("1", "1");
            roomService.leaveRoom("2", "1");
            roomService.leaveRoom("3", "1");
            roomService.joinRoom("1", "1");
            roomService.joinRoom("2", "1");
            roomService.joinRoom("3", "1");
            countDownLatch.countDown();
        }
    }
}
